package com.laiketui.admin.store.controller.store;

import com.laiketui.common.mapper.MchModelMapper;
import com.laiketui.common.utils.tool.cache.RedisDataTool;
import com.laiketui.core.cache.RedisUtil;
import com.laiketui.core.exception.LaiKeAPIException;
import com.laiketui.domain.lktconst.DictionaryConst;
import com.laiketui.domain.lktconst.ErrorCode;
import com.laiketui.domain.mch.AdminModel;
import com.laiketui.domain.mch.MchModel;
import com.laiketui.domain.user.User;
import com.laiketui.domain.vo.MainVo;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

public class AdminBaseController {
    @Autowired
    MchModelMapper mchModelMapper;
    @Autowired
    private RedisUtil redisUtil;

    @Value("${debugger.local.test:false}")
    private boolean test;

    public AdminModel currentAdmin(MainVo params){
        AdminModel redisAdminUserCache;
        if(test){
            redisAdminUserCache = new AdminModel();
            redisAdminUserCache.setId(1);
            redisAdminUserCache.setStore_id(1);
        }else{
             redisAdminUserCache = RedisDataTool.getRedisAdminUserCache(params.getAccessId(), redisUtil);
        }
        if (redisAdminUserCache == null) {
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_FFRQ, "非法入侵");
        }
        return redisAdminUserCache;
    }

    public User currentUser(MainVo params){
        User user;
        if(test){
            user = testUser();;
        }else {
             user = RedisDataTool.getRedisUserCache(params.getAccessId(), redisUtil, true);
        }
        return user;
    }


    private static @NotNull User testUser() {
        User user = new User();
        user.setUser_id("user829");
        user.setStore_id(1);
        user.setRole_id(379);
        user.setMobile("13800000000");
        user.setUser_name("百货自营");
        return user;
    }
}
